<template>
  <el-select v-model="value" placeholder="请选择" @change="changeValue($event)" clearable >
    <el-option
      v-for="item in staffs"
      :key="item.code"
      :label="item.name"
      :value="item.code"
    >
      <span style="float:left">{{ item.name }}</span>
    <span style="float: right ; color: #8492a6; font-size: 12px">&nbsp;&nbsp;{{ groupNameFormatter(item) }}</span>
    </el-option>
  </el-select>
</template>
<script>
  import request from '@/utils/request'
  export default {
    data() {
      return {
        value: '',
        staffs: [],
        callbackMethod: ''
      }
    },
    created() {
    },
    methods: {
      groupNameFormatter(row) {
        let gropName = row.branchName;
        if(row.departmentName)
          gropName =gropName + ' / ' + row.departmentName;
        return gropName
      },

      changeValue(e) {
        const staff = this.staffs.find(i => i.code === e)
        this.$emit(this.callbackMethod, staff)
        this.$emit("getRoleList", staff.branchCode)
      },
      setSelectValue(value) {
        this.value = value
      },
      init(staffs, callbackMethod) {
        this.staffs = staffs
        this.callbackMethod = callbackMethod
      }
    }
  }
</script>

